package org.ruoyi.interview.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.common.core.utils.MapstructUtils;
import org.ruoyi.common.core.utils.StringUtils;
import org.ruoyi.common.log.annotation.Log;
import org.ruoyi.common.log.enums.BusinessType;
import org.ruoyi.common.mybatis.core.page.PageQuery;
import org.ruoyi.common.mybatis.core.page.TableDataInfo;
import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.interview.domain.bo.InterviewQuestionFieldBo;
import org.ruoyi.interview.domain.vo.InterviewQuestionFieldVo;
import org.ruoyi.interview.service.IInterviewQuestionFieldService;

import jakarta.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 题目领域Controller
 *
 * @author ruoyi
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/interview/field")
public class InterviewQuestionFieldController extends BaseController {

    private final IInterviewQuestionFieldService interviewQuestionFieldService;

    /**
     * 查询题目领域列表
     */
    @SaCheckPermission("interview:field:list")
    @GetMapping("/list")
    public TableDataInfo<InterviewQuestionFieldVo> list(InterviewQuestionFieldBo bo, PageQuery pageQuery) {
        return interviewQuestionFieldService.selectInterviewQuestionFieldList(bo, pageQuery);
    }

    /**
     * 导出题目领域列表
     */
    @SaCheckPermission("interview:field:export")
    @Log(title = "题目领域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(InterviewQuestionFieldBo bo, HttpServletResponse response) {
        List<InterviewQuestionFieldVo> list = interviewQuestionFieldService.selectInterviewQuestionFieldList(bo);
        // ExcelUtil.exportExcel(list, "题目领域", InterviewQuestionFieldVo.class, response); // 如需导出功能请取消注释
    }

    /**
     * 获取题目领域详细信息
     *
     * @param fieldId 题目领域主键
     */
    @SaCheckPermission("interview:field:query")
    @GetMapping("/{fieldId}")
    public R<InterviewQuestionFieldVo> getInfo(@PathVariable("fieldId") Long fieldId) {
        return R.ok(interviewQuestionFieldService.selectInterviewQuestionFieldById(fieldId));
    }

    /**
     * 新增题目领域
     */
    @SaCheckPermission("interview:field:add")
    @Log(title = "题目领域", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(org.ruoyi.common.core.validate.AddGroup.class) @RequestBody InterviewQuestionFieldBo bo) {
        return toAjax(interviewQuestionFieldService.insertInterviewQuestionField(bo) ? 1 : 0);
    }

    /**
     * 修改题目领域
     */
    @SaCheckPermission("interview:field:edit")
    @Log(title = "题目领域", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(org.ruoyi.common.core.validate.EditGroup.class) @RequestBody InterviewQuestionFieldBo bo) {
        return toAjax(interviewQuestionFieldService.updateInterviewQuestionField(bo) ? 1 : 0);
    }

    /**
     * 删除题目领域
     *
     * @param fieldIds 题目领域主键串
     */
    @SaCheckPermission("interview:field:remove")
    @Log(title = "题目领域", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fieldIds}")
    public R<Void> remove(@PathVariable Long[] fieldIds) {
        return toAjax(interviewQuestionFieldService.deleteInterviewQuestionFieldByIds(Arrays.asList(fieldIds)) ? 1 : 0);
    }
}